package analyticsServer;

import java.util.List;
import server.data.Bid;

/**
 * Class for Events concerning Bids (Bid placed, overbid and won)
 * 
 * @author Group 95
 */
public class BidEvent extends Event
{
    private Bid bid;
    
    public static final String BID_PLACED="BID_PLACED";
    public static final String BID_OVERBID="BID_OVERBID";
    public static final String BID_WON="BID_WON";
    
    
    public BidEvent(final String server,final String type,final long timestamp,final Bid bid)
    {
        super(server,type,timestamp);
        this.bid=bid;
    }

    
    @Override
    public String toString()
    {
        String strRet=super.toString();
        if(type.equals(BID_PLACED))
        {
            strRet+="user "+bid.getBidder()+" placed bid "+bid.getdPrice()+" on auction "+bid.getAuctionId();
        }
        else if(type.equals(BID_OVERBID))
        {
            strRet+="user "+bid.getBidder()+" has been overbid with "+bid.getdPrice()+" on auction "+bid.getAuctionId();
        }
        else if(type.equals(BID_WON))
        {
            strRet+="user "+bid.getBidder()+" won bidding on auction "+bid.getAuctionId()+" with "+bid.getdPrice();
        }
        return strRet;
    }
    
    @Override
    public List<StatisticsEvent> calculate(final EventCalculator calculator)
    {
        return calculator.calculate(this);
    }
    
    public double getPrice()
    {
        double dRet=0.0;
        if(this.bid!=null)
        {
            dRet = bid.getdPrice();
        }
        return dRet;
    }
}
